package com.mz.mattress.client.plan;

import java.time.LocalTime;

// 时间段定义和比例配置

/**
 * 上午时段（9:30-12:00）：约占15%
 * 午间高峰（12:00-14:30）：约占15%
 * 下午平峰（14:30-17:30）：约占30%
 * 晚间高峰（17:30-21:30）：约占40%
 */
public enum TimeSegment {

    MORNING(LocalTime.of(9, 30), LocalTime.of(12, 0), 0.15, "上午时段"),
    NOON_PEAK(LocalTime.of(12, 0), LocalTime.of(14, 30), 0.15, "午间高峰"),
    AFTERNOON(LocalTime.of(14, 30), LocalTime.of(17, 30), 0.30, "下午平峰"),
    EVENING_PEAK(LocalTime.of(17, 30), LocalTime.of(21, 30), 0.40, "晚间高峰"),
    OTHER_TIME(null, null, 0.00, "其他时间"); // 0% 任务量

    private final LocalTime start;
    private final LocalTime end;
    private final double proportion;
    private final String description;

    TimeSegment(LocalTime start, LocalTime end, double proportion, String description) {
        this.start = start;
        this.end = end;
        this.proportion = proportion;
        this.description = description;
    }

    public static TimeSegment getSegment(LocalTime time) {
        for (TimeSegment segment : values()) {
            if (segment.start != null && segment.end != null &&
                    !time.isBefore(segment.start) && time.isBefore(segment.end)) {
                return segment;
            }
        }
        return OTHER_TIME;
    }

    public double getProportion() {
        return proportion;
    }

    public String getDescription() {
        return description;
    }

    public LocalTime getStart() {
        return start;
    }

    public LocalTime getEnd() {
        return end;
    }
}